package com.crom.android.lottebaseball;


import android.app.AlarmManager;
import android.app.Service;
import android.content.ContentValues;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.os.SystemClock;
import android.util.Log;
import android.widget.Toast;
import android.app.PendingIntent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;



public class Alarm extends Service {
	
	public static final String KEY_NOTI_TIME = "notitime_pref";
	private final String logTag = "Crom_Alarm";
	
	public boolean HOMEGAME = false;
	public int LEAD = -1;
	public static String lotteInfo;
	public static String awayteamInfo;
	public static int lotteBeforeScore=0;
	public static int awayteamBeforeScore=0;
	public static int TICK =0;
	public static int test =0;
	
	public class LocalBinder extends Binder{
		
		Alarm getService(){
			return Alarm.this;
		}
	}
	
	 @Override
	 public void onCreate() {
	  // TODO Auto-generated method stub
	  super.onCreate();
	    
		
	 }
	 
	 @Override
	 public int onStartCommand(Intent intent, int flags, int startId){
		 
		 Log.i(logTag, "Alarm Service start id" + startId + ":" + intent);
		 
		 int interval;
		 if(settingMenu.prefs  != null){
			 interval = settingMenu.prefs.getInt(KEY_NOTI_TIME, 8);
	
		 }else{
			 settingMenu.prefs = getSharedPreferences("PrefName", MODE_PRIVATE);
			 interval = settingMenu.prefs.getInt(KEY_NOTI_TIME, 8);
	
		 }

			
	      Intent i = new Intent(Alarm.this, AlarmService_Service.class);
	      PendingIntent sender = PendingIntent.getBroadcast(Alarm.this,
	              0, i, 0);
	      
	      long firstTime = SystemClock.elapsedRealtime();
	      //firstTime += 10*1000; /* for Test */
	      firstTime += 300*1000 ; /* Normal */
	      
	      AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
	      am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
	                      firstTime, interval*60*1000 , sender); /* 480*1000 8min*/
          			//	  firstTime, 10*1000 , sender); /* For Test*/	      
		 return START_STICKY;
			 
	}
	 @Override
	 public void onDestroy() {
	 
	 }



	@Override
	public IBinder onBind(Intent intent) {
		// TODO Auto-generated method stub
		return mBinder;
		
	}
	
	 // This is the object that receives interactions from clients.  See
    // RemoteService for a more complete example.
    private final IBinder mBinder = new LocalBinder();
	


}

